package com.easy.component.network.interceptor;

import com.easy.component.network.EasyNetWork;

import java.io.IOException;
import java.util.Map;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * 描述: {http头设置拦截器}
 * 作者:jack-song
 * 创建日期: 2017/9/11 21:21
 * 修改日期: 2017/9/11
 * 版本: {版本}
 */
public class HeadersInterceptor implements Interceptor {

    @Override
    public Response intercept(Chain chain) throws IOException {
        Request.Builder builder = chain.request().newBuilder();
        Map<String, String> header = EasyNetWork.getInstance().getHeader();
        if (null != header) {
            for (Map.Entry<String, String> entry : header.entrySet()) {
                builder.addHeader(entry.getKey(), entry.getValue());
            }
        }
        return chain.proceed(builder.build());
    }
}
